<?php


namespace app\manage\controller;

use app\manage\model\Token;
use think\Validate;

class Examine
{

    public function __construct()
    {
        $this->token=new Token();
        $this->examine=new \app\manage\model\Examine();

    }

    /**
     * 入驻审核列表   type  1=待审核  2=审核记录
     */
    public function examineList(){
        $param=input();
        $page=empty($param['current_page']) ? 1 : $param['current_page'];
        $page_size=empty($param['page_num']) ? 10: $param['page_num'];
        $type=empty($param['type']) ? 1: $param['type'];

        $returnData=$this->examine->storeList($param,$page,$page_size,$type);

        returnJson(200,'success',$returnData);
    }

    /**
     * 入驻详情
     */
    public function examineDetail(){
        $store_id=input('sa_id');

        $returnData=$this->examine->storeDetail($store_id);
        returnJson(200,'success',$returnData);
    }

    /**
     * 入驻---审核通过 拒绝  type  1=通过  2=拒绝
     */
    public function examine(){
        $param=input();
        $store_id=$param['sa_id'];
        $type=$param['type'];
        //dump($param);exit;
        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->review($store_id,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 入驻---批量审核通过，拒绝
     */
    public function  examineAll(){
        $param=input();
        $ids=$param['sa_ids'];//数组
        $type=$param['type'];

        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->reviewAll($ids,$data);

        returnJson(200,'操作成功');
    }

    /**
     *入驻-删除操作
     */
    public function examineDel(){
        $store_id=input('sa_id');
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->review($store_id,$data);
        returnJson(200,'操作成功');

    }

    /**
     * 入驻---批量删除
     */
    public function examineDelAll(){
        $ids=input('sa_ids');//数组
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->reviewAll($ids,$data);
        returnJson(200,'操作成功');

    }

    /**
     * 查看入驻审核拒绝原因
     */
    public function refuse(){
        $store_id=input('sa_id');
        $returnData=$this->examine->refuseDetail($store_id);
        returnJson(200,'success',$returnData);
    }


    /**
     * 实名认证列表  type 1=待审核  2=审核记录
     */
    public function authList(){
        $param=input();
        $page=empty($param['current_page']) ? 1 : $param['current_page'];
        $page_size=empty($param['page_num']) ? 10: $param['page_num'];
        $type=empty($param['type']) ? 1: $param['type'];

        $returnData=$this->examine->realList($param,$page,$page_size,$type);

        returnJson(200,'success',$returnData);
    }

    /**
     * 实名认证-------查看身份信息
     */
    public function identity(){
        $in_id=input('in_id');
        $field='mi.in_id,mi.card,mi.real_name,mi.card_just,mi.card_back,m.mobile,mi.fail_reason';
        $returnData=$this->examine->realDetail($in_id,$field);
        returnJson(200,'success',$returnData);

    }

    /**
     * 实名认证--------查看拒绝原因
     */
    public function realReason(){
        $in_id=input('in_id');
        $field='mi.fail_reason';
        $returnData=$this->examine->realDetail($in_id,$field);
        returnJson(200,'success',$returnData);
    }

    /**
     *实名认证-----通过、拒绝操作  type 1= 通过  2=拒绝
     */
    public function realOperate(){
        $param=input();
        $store_id=$param['in_id'];
        $type=$param['type'];
        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->realOperate($store_id,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 实名认证-批量操作  通过 拒绝  type 1=通过  2=拒绝
     */
    public function realOperateAll(){
        $param=input();
        $ids=$param['in_ids'];//数组
        $type=$param['type'];

        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->realOperateAll($ids,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 实名认证  ---删除
     */
    public function realDel(){
        $store_id=input('in_id');
        $data['update_time']=time();
        $data['status']=0;
        $data['card']='';
        $data['card_just']='';
        $data['card_back']='';

        $this->examine->realOperate($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 实名认证-----批量删除
     */
    public function realDelAll(){
        $store_id=input('in_ids');//数组
        $data['update_time']=time();
        $data['status']=0;
        $data['card']='';
        $data['card_just']='';
        $data['card_back']='';

        $this->examine->realOperateAll($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 股东认证列表  type 1=待审核  2=审核记录
     */
    public function partnerList(){
        $param=input();
        $page=empty($param['current_page']) ? 1 : $param['current_page'];
        $page_size=empty($param['page_num']) ? 10: $param['page_num'];
        $type=empty($param['type']) ? 1: $param['type'];

        $returnData=$this->examine->shareList($param,$page,$page_size,$type);

        returnJson(200,'success',$returnData);
    }

    /**
     * 股东认证-------查看营业执照
     */
    public function business(){
        $in_id=input('pc_id');
        $field='pc.pc_id,pc.partner_name,pc.company_name,pc.business_license,pc.fail_reason,
        pc.credit_code,pc.create_time,mi.real_name';
        $returnData=$this->examine->shareDetail($in_id,$field);
        returnJson(200,'success',$returnData);

    }

    /**
     * 股东认证--------查看拒绝原因
     */
    public function partnerReason(){
        $in_id=input('pc_id');
        $field='fail_reason';
        $returnData=$this->examine->shareDetail($in_id,$field);
        returnJson(200,'success',$returnData);
    }

    /**
     *股东认证-----通过、拒绝操作  type 1= 通过  2=拒绝
     */
    public function partnerOperate(){
        $param=input();
        $store_id=$param['pc_id'];
        $type=$param['type'];
        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->shareOperate($store_id,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 股东认证-批量操作  通过 拒绝  type 1=通过  2=拒绝
     */
    public function partnerOperateAll(){
        $param=input();
        $ids=$param['pc_ids'];//数组
        $type=$param['type'];

        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->shareOperateAll($ids,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 股东认证  ---删除
     */
    public function partnerDel(){
        $store_id=input('pc_id');
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->shareOperate($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 股东认证-----批量删除
     */
    public function partnerDelAll(){
        $store_id=input('pc_ids');//数组
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->shareOperateAll($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 推客认证列表  type 1=待审核  2=审核记录
     */
    public function twitterList(){
        $param=input();
        $page=empty($param['current_page']) ? 1 : $param['current_page'];
        $page_size=empty($param['page_num']) ? 10: $param['page_num'];
        $type=empty($param['type']) ? 1: $param['type'];

        $returnData=$this->examine->twitterList($param,$page,$page_size,$type);

        returnJson(200,'success',$returnData);
    }

    /**
     * 推客认证  ---删除
     */
    public function twitterDel(){
        $store_id=input('t_id');
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->twitterOperate($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 推客认证-----批量删除
     */
    public function twitterDelAll(){
        $store_id=input('t_ids');//数组
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->twitterOperateAll($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 推客认证--------查看拒绝原因
     */
    public function twitterReason(){
        $in_id=input('t_id');
        //$field='t_id,twitter_name,phone,address,credit_code,create_time,fail_reason';
        $field='ai.ai_id as t_id,ai.invest_name as twitter_name,m.mobile as phone,ai.invest_address as address,
        ai.create_time,ai.fail_reason,ai.invest_code as credit_code';
        $returnData=$this->examine->twitterDetail($in_id,$field);
        returnJson(200,'success',$returnData);
    }

    /**
     *推客认证-----通过、拒绝操作  type 1= 通过  2=拒绝
     */
    public function twitterOperate(){
        $param=input();
        $store_id=$param['t_id'];
        $type=$param['type'];
        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->twitterOperate($store_id,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 推客认证-批量操作  通过 拒绝  type 1=通过  2=拒绝
     */
    public function twitterOperateAll(){
        $param=input();
        $ids=$param['t_ids'];//数组
        $type=$param['type'];

        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->twitterOperateAll($ids,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 发票认证列表  type 1=待审核  2=审核记录
     */
    public function invoiceList(){
        $param=input();
        $page=empty($param['current_page']) ? 1 : $param['current_page'];
        $page_size=empty($param['page_num']) ? 10: $param['page_num'];
        $type=empty($param['type']) ? 1: $param['type'];

        $returnData=$this->examine->invoiceList($param,$page,$page_size,$type);

        returnJson(200,'success',$returnData);
    }

    /**
     * 发票认证  ---删除
     */
    public function invoiceDel(){
        $store_id=input('i_id');
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->invoiceOperate($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 发票认证-----批量删除
     */
    public function invoiceDelAll(){
        $store_id=input('i_ids');//数组
        $data['update_time']=time();
        $data['is_delete']=2;

        $this->examine->invoiceOperateAll($store_id,$data);
        returnJson(200,'操作成功');
    }

    /**
     * 发票认证--------查看拒绝原因
     */
    public function invoiceReason(){
        $in_id=input('i_id');
        $field='fail_reason';
        $returnData=$this->examine->invoiceDetail($in_id,$field);
        returnJson(200,'success',$returnData);
    }

    /**
     * 发票认证--------查看详情
     */
    public function invoiceDetail(){
        $in_id=input('i_id');
        $field='invoice_rise,credit_code,company_name,company_address,reg_phone,bank_name,bank,fail_reason,
        price,i_type';
        $returnData=$this->examine->invoiceDetail($in_id,$field);
        returnJson(200,'success',$returnData);
    }

    /**
     *发票认证-----通过、拒绝操作  type 1= 通过  2=拒绝
     */
    public function invoiceOperate(){
        $param=input();
        $store_id=$param['i_id'];
        $type=$param['type'];
        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->invoiceOperate($store_id,$data);

        returnJson(200,'操作成功');
    }

    /**
     * 发票认证-批量操作  通过 拒绝  type 1=通过  2=拒绝
     */
    public function invoiceOperateAll(){
        $param=input();
        $ids=$param['i_ids'];//数组
        $type=$param['type'];

        if($type==1){
            $data['status']=1;
            $data['update_time']=time();
        }else{
            $validate = new Validate([
                ['fail_reason', 'require', '拒绝原因不能为空'],
            ]);
            if(!$validate->check($param))
            {
                returnJson(-2003,$validate->getError());
            }
            $data['fail_reason']=$param['fail_reason'];
            $data['status']=3;
            $data['update_time']=time();
        }

        $this->examine->invoiceOperateAll($ids,$data);

        returnJson(200,'操作成功');
    }
}